package com.fare.taluo.core.domain.crawl.statistics;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.dayatang.domain.InstanceFactory;
import com.dayatang.domain.QuerySettings;
import com.fare.taluo.core.domain.BaseEntity;

/**
 * @引擎统计-抓取失败统计
 * 
 */

@SuppressWarnings("serial")
@javax.persistence.Entity
@Table(name = "STATUS_TASK")
public class StatusTaskEntity extends BaseEntity<FailtureTaskEntity> implements com.dayatang.domain.Entity{
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = FDC_SEQ_GEN)
	@SequenceGenerator(name = FDC_SEQ_GEN, sequenceName = FDC_SEQUENCE)
	@Column(name = "GRABCHANNEL")
	private String grabchannel;
	@Column(name = "STATUS")
	private String status;
	@Column(name = "NUM")
	private Long num;
	
	public String getGrabchannel() {
		return grabchannel;
	}

	public void setGrabchannel(String grabchannel) {
		this.grabchannel = grabchannel;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Long getNum() {
		return num;
	}

	public void setNum(Long num) {
		this.num = num;
	}


	@Override
	public Serializable getId() {
		// TODO Auto-generated method stub
		return null;
	}
//	private static StatusTaskEntityRepository statusTaskEntityRepository = InstanceFactory.getInstance(StatusTaskEntityRepository.class);
	private static StatusTaskEntityRepository getStatusTaskEntityRepository(){
		return InstanceFactory.getInstance(StatusTaskEntityRepository.class);
	}
	/**
	 * @return查询所有
	 */
	public List<StatusTaskEntity> getStatusTaskByPage(){
		return getStatusTaskEntityRepository().getStatusTaskByPage();
	}

	@Override
	public boolean isNew() {
		return getId() == null ;
	}

	@Override
	public boolean existed() {
		if (isNew()) {
			return false;
		}
		return getRepository().exists(getClass(), getId());
	}

	@Override
	public boolean notExisted() {
		return ! existed();
	}
	
	@Override
	public boolean existed(String propertyName, Object propertyValue) {
		List<?> entities = getRepository().find(QuerySettings.create(getClass()).eq(propertyName, propertyValue)); 
		return !(entities.isEmpty());
	}
}
